use crate::code::length::Length;
use darling::FromField;

#[derive(Debug, Default, FromField)]
#[darling(attributes(validate))]
pub(crate) struct FieldAttrs {
    pub(crate) length: Option<Length>,
    pub(crate) label: Option<String>,
}

pub(crate) struct Validator<'a> {
    pub(crate) attr: Option<FieldAttrs>,
    pub(crate) name: &'a syn::Ident,
    pub(crate) ty: &'a syn::Type,
}

pub(crate) fn get_fields_attr(field: &syn::Field) -> Option<Validator> {
    Some(Validator {
        attr: FieldAttrs::from_field(field).ok(),
        name: field.ident.as_ref().unwrap(),
        ty: &field.ty,
    })
}
